package com.clz.appdesign.appdependence.mvp_dagger;


import com.clz.appdesign.appdependence.base.BaseActivity;
import com.clz.appdesign.appdependence.base.mvp.BasePresenter;

import javax.inject.Inject;

/**
 * @author clz
 * @desc 初始化P，并且连接V，在onDestroy()生命周期中释放P中引用的V。
 */
public abstract class MvpDaggerActivity<V, P extends BasePresenter<V>> extends BaseActivity {
    @Inject
    protected P mPresenter;

    @Override
    protected void beforeInit() {
        super.beforeInit();
        initInject();
    }

    protected abstract void initInject();

    @Override
    protected void onResume() {
        super.onResume();
        if (null != mPresenter) {
            mPresenter.attach((V) this);
        }
    }

    @Override
    protected void onDestroy() {
        if (null != mPresenter) {
            mPresenter.detach();
            mPresenter = null;
        }
        super.onDestroy();
    }

}
